Skip to content

feat(auth): sign a user out from their access token as an admin - #594

Merged
Tr00d merged 1 commit into
masterfrom
feat/auth.admin.sign_out
Oct 29, 2026
Merged

Tr00d merged 1 commit into
masterfrom
feat/auth.admin.sign_out

Conversation

@Tr00d

@Tr00d Tr00d commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A server holding the admin client can sign a user out from their access token, revoking that user's sessions in the chosen scope.

Capability: auth.admin.sign_out: Admin Sign Out.

Public API

// IGotrueAdminClient<TUser>
Task SignOutAsync(string accessToken, Constants.SignOutScope scope = Constants.SignOutScope.Global, CancellationToken cancellationToken = default);
var admin = new AdminClient(serviceRoleKey, new ClientOptions { Url = authUrl, Headers = { ["apikey"] = anonKey } });
await admin.SignOutAsync(userAccessToken, Constants.SignOutScope.Global);

New types: none. IGotrueApi<TUser, TSession> gains SignOutAsync(string jwt, SignOutScope, CancellationToken), which carries the cancellation token. The existing SignOut(jwt, scope) is unchanged and shares its request code with the new member.

Behavior

Operation POST /logout?scope=global|local|others with an empty {} body. Authorization: Bearer <user access token>; apikey is the configured header. The service key is not sent: the auth server authenticates /logout with the user's token and does not check for admin.
Input accessToken, required. scope, default Global.
Output 204 → completes. Refresh tokens of the revoked sessions stop working. Access tokens already issued stay valid until they expire.
Checks before the request ArgumentException when accessToken is null, empty or whitespace. Otherwise the server would answer 401 no_authorization.
Failures GotrueException: ErrorCode = session_not_found (403) when the token's session was already revoked; ErrorCode = user_not_found (403) when its user was deleted; Reason = AdminTokenRequired (403 bad_jwt) when the token is expired, malformed or carries no user.
State None. The admin client holds no session.

Deviations from supabase-js

None in behavior. Like supabase-js's auth.admin.signOut, failures are reported rather than swallowed, unlike a client's own sign-out, which ignores 401/403/404. The scope is an enum, so the invalid-scope error supabase-js throws cannot happen.

Tests

Tier Class Pins
E2E SignOut/AdminSignOutTests Signing out a freshly signed-up user's token revokes the session (GetUser → session_not_found). Signing out an already revoked session → ErrorCode = session_not_found.
Contract SignOut/AdminSignOutContractTests POST /logout with the user's token as Bearer and the configured apikey. Global by default. Each scope's query value. 403 session_not_found surfaced. A cancelled token sends nothing.
Unit SignOut/AdminSignOutAccessTokenTests Null, empty and whitespace tokens rejected before the request

Changed-line coverage: 100% (8 lines). Mutation: 7/7 killed on changed lines, 0 survivors.

No wire-shape approval snapshot: the body is always {}. Existing stateless sign-out tests cover it.

Layout

Sign-out adds no types, so it has no production folder. Its tests sit in packages/Gotrue/Gotrue.Tests/SignOut/, named after SignOutAsync. The classes keep the Admin prefix to set them apart from the client's own session sign-out tests (Authentication/SignOutLocalSessionTests).

Notes

  • IGotrueStatelessClient.SignOut(accessToken, options, scope) already made the same request, but on the stateless client, with no Async suffix and no cancellation token. It is left as is.
  • v9 follow-up: bad_jwt maps to FailureHint.Reason.AdminTokenRequired globally. For this method the bad token is the user's, so AdminTokenRequired is misleading here. The raw code stays available on ErrorCode. Changing the mapping changes the error contract of every admin method, so it belongs in v9.

@Tr00d
Tr00d force-pushed the feat/auth.admin.sign_out branch from cc6f3ec to 2c88ac8 Compare October 29, 2026 14:29
@Tr00d
Tr00d marked this pull request as ready for review October 29, 2026 15:00
@Tr00d
Tr00d force-pushed the feat/auth.admin.sign_out branch from 2c88ac8 to a6f2b1e Compare October 29, 2026 15:03
@Tr00d
Tr00d merged commit 540e40f into master Oct 29, 2026
3 checks passed
@Tr00d
Tr00d deleted the feat/auth.admin.sign_out branch October 29, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant